<script setup>
const props = defineProps({
  accurate: Object,
  vague: Object,
});

const emit = defineEmits([
  'back',
  'updateResume',
  'addPositionBtn',
  'update:accurate',
  'update:vague',
]);

const back = () => {
  emit('back', false);
};

const ignoreBtn = (arrName, index) => {
  props[arrName].data.splice(index, 1);
  props[arrName].total--;
  emit(`update:${arrName}`, props[arrName]);
  if (!props.accurate.total && !props.vague.total) {
    back();
  }
};

const allIgnoreBtn = () => {
  props.accurate.data = [];
  props.accurate.total = 0;
  props.vague.data = [];
  props.vague.total = 0;
  emit(`update:accurate`, props.accurate);
  emit(`update:vague`, props.vague);
  back();
};

const updateResumeBtn = (uid) => {
  emit('updateResume', uid);
};
</script>

<template>
  <div class="duplicate-check">
    <template v-if="props.accurate.total">
      <div class="accurate-duplicate-checking">
        <h3 class="title">精准查重：{{ props.accurate.total }}</h3>
        <div
          style="margin-top: 20px"
          v-for="(item, index) in props.accurate.data"
          :key="item.uid"
        >
          <div class="information">
            <img :src="item.photoUrl" />
            <div>
              <p>姓名: {{ item.name }} (更新时间: {{ item.modifyDate }})</p>
              <p>{{ item.lastWork }}</p>
              <p>{{ item.positionProcessDetail }}</p>
            </div>
          </div>
          <div>
            <el-button @click="updateResumeBtn(item.uid)" type="primary"
              >更新简历</el-button
            >
            <el-button @click="emit('addPositionBtn', item.uid)">加入职位</el-button>
            <el-button @click="ignoreBtn('accurate', index)">忽略</el-button>
          </div>
        </div>
      </div>
    </template>
    <template v-if="props.vague.total">
      <div class="fuzzy-duplicate-checking">
        <h3 class="title">模糊查重:{{ props.vague.total }}</h3>
        <div
          style="margin-top: 20px"
          v-for="(item, index) in props.vague.data"
          :key="item.uid"
        >
          <div class="information">
            <img :src="item.photoUrl" />
            <div>
              <p>姓名: {{ item.name }} (更新时间: {{ item.modifyDate }})</p>
              <p>{{ item.lastWork }}</p>
              <p>{{ item.positionProcessDetail }}</p>
            </div>
          </div>
          <div>
            <el-button type="primary" @click="updateResumeBtn(item.uid)"
              >更新简历</el-button
            >
            <el-button @click="emit('addPositionBtn', item.uid)">加入职位</el-button>
            <el-button @click="ignoreBtn('vague', index)">忽略</el-button>
          </div>
        </div>
      </div>
    </template>
  </div>
  <div>
    <el-button type="primary" @click="allIgnoreBtn">全部忽略</el-button>
    <el-button @click="back">返回</el-button>
  </div>
</template>

<style lang="scss" scoped>
.duplicate-check {
  padding: 15px;
  width: 90%;
  .accurate-duplicate-checking {
    margin-bottom: 20px;
  }
  .title {
    border-bottom: 1px solid #ccc;
  }
  .information {
    display: flex;
    margin-bottom: 15px;
    img {
      width: 54px;
      height: 54px;
      margin-right: 20px;
    }
  }
}
</style>
